package com.stone.framework.basic.param.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import com.stone.framework.basic.param.entity.BusinessParam;
import com.stone.framework.core.util.JpaSpecifications;

@Repository
public interface BusinessParamRepository
    extends JpaRepository<BusinessParam, Long>, JpaSpecificationExecutor<BusinessParam> {

    default Page<BusinessParam> findAll(BusinessParam entity, Pageable pageable) {
        return this.findAll(Specification.where(JpaSpecifications.<BusinessParam>contains("key", entity.getKey()))
            .and(JpaSpecifications.contains("value", entity.getValue()))
            .and(JpaSpecifications.contains("desc", entity.getDesc()))
            .and(JpaSpecifications.equals("state", entity.getState())), pageable);
    }

    List<BusinessParam> findByKey(String key);

}
